﻿
<!--note: when reference 'system' namespace, 'assembly=mscorlib' is indispensable-->
    <Window x:Class="_12.BindToList.ObjectDataProvider"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:_12.BindToList"
        Title="ObjectDataProvider" Height="300" Width="389">
    <Window.Resources>
        <!--note: implict style which targets all control, MAKE NO EFFECT-->
        <!--
        <Style TargetType="Control">
            <Setter Property="Margin" Value="10"/>
        </Style>
        -->
        <!--note: it seems that implict style is only meaningful for specific controls
        not for all generic all controls-->
        <Style TargetType="Button">
            <Setter Property="Margin" Value="5"/>
        </Style>
        <Style TargetType="ListBox">
            <Setter Property="Margin" Value="5"/>
            <Setter Property="DisplayMemberPath" Value="Name"/>
            <Setter Property="IsSynchronizedWithCurrentItem" Value="True"/>
        </Style>
        <!--note: both static method and instance method can work as object provider
        however, I think static method make sense,
        the key issue is how to pass in a parameter to construct a special instance
        and then call method on it-->
        <ObjectDataProvider x:Key="staticLoader"
                            ObjectType="{x:Type local:PeopleLoader}"
                            MethodName="StaticLoad"/>
        <ObjectDataProvider x:Key="instanceLoader"
                            ObjectType="{x:Type local:PeopleLoader}"
                            MethodName="InstanceLoad">
            <ObjectDataProvider.MethodParameters>
                <sys:Int32>9</sys:Int32>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <GroupBox Header="StaticMethod">
            <DockPanel>
                <Button Content="Next" DockPanel.Dock="Bottom"
                        Name="btnNext"
                        Click="btnNext_Click"/>
                <ListBox DockPanel.Dock="Top"
                         ItemsSource="{Binding Source={StaticResource staticLoader}}"/>
            </DockPanel>
        </GroupBox>
        <GroupBox Header="InstanceMethod" Grid.Column="1">
            <DockPanel>
                <Button Content="Previous" DockPanel.Dock="Bottom"
                        Name="btnPrevious"
                        Click="btnPrevious_Click"/>
                <ListBox DockPanel.Dock="Top"
                         ItemsSource="{Binding Source={StaticResource instanceLoader}}"/>
            </DockPanel>
        </GroupBox>
        
    </Grid>
</Window>
